package com.bwie.controller;

import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginVo;
import com.bwie.vo.PageInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2025/6/19 14:05
 */

@RestController
@RequestMapping("/user/index")
@Slf4j
public class IndexController {

    @Autowired
    TbUserService tbUserService;

    /**
     * @description 管理员登录
     * @params [loginVo]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/6/19 14:11
     */
    @PostMapping("/adminLogin")
    public R adminLogin(@RequestBody @Validated LoginVo loginVo) {
        return tbUserService.login(loginVo);
    }

    /**
     * @description 根据用户ID获取用户的菜单树
     * @params [userId]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/6/19 15:55
     */
    @PostMapping("/getMenuTree")
    public R getMenuTree() {
        return tbUserService.getMenuTree();
    }

    /**
     * @description 分页获取商户信息
     * @params [pageInfoVo]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/6/19 16:48
     */
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageInfoVo pageInfoVo) {
        return tbUserService.getUserList(pageInfoVo);
    }

    /**
     * @description 获取当前登录用户的信息
     * @params []
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/7/1 10:52
     */
    @PostMapping("/getUserInfo")
    public R getUserInfo() {
        return tbUserService.getUserInfo();
    }

    @PostMapping("/getUserInfoById/{userId}")
    public R getUserInfoById(@PathVariable("userId") Integer userId) {
        return tbUserService.getUserInfoById(userId);
    }

    /**
     * @description 使用rest-high-level-client创建索引
     * @params []
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/7/4 17:22
     */
    @PostMapping("/createIndex")
    public R createIndex() {
        return tbUserService.createIndex();
    }

    /**
     * @description 用户签到
     * @params []
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/7/7 10:55
     */
    @PostMapping("/signIn")
    public R signIn() {
        return tbUserService.signIn();
    }

    /**
     * @description 用户抽奖扣积分
     * @params [userId, score]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/7/7 11:22
     */
    @PostMapping("/joinActiveSubScore/{userId}/{score}")
    public R joinActiveSubScore(@PathVariable("userId") Integer userId, @PathVariable("score") Integer score) {
        return tbUserService.joinActiveSubScore(userId,  score);
    }
}
